package com.thf.controller;

import com.alibaba.fastjson.JSON;
import com.thf.model.ResultData;
import com.thf.service.UserService;
import com.thf.util.Tool;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Controller
public class UserDelController {

    @Resource
    private UserService userService ;
    @RequestMapping("/back/user/del")
    @ResponseBody
    protected String doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //     0。乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //        1.得到前端传递过来的数据
        String uid = req.getParameter("id");
        //        -返回值
        ResultData result = userService.delete(Tool.stringToInt(uid));
//       反馈给前端--返回值
        String resJson = JSON.toJSONString(result);
//        resp.getWriter().println(resJson);
        return resJson ;
    }
}
